package com.wanaofu.model;

import java.io.Serializable;
import java.math.BigDecimal;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

@Entity
@Table(name = "product_info",uniqueConstraints ={@UniqueConstraint(columnNames={"p_code"})})
public class ProductInfo  extends AbstractBaseEntity implements Serializable{
	private static final long serialVersionUID = -1153875495512129496L;
	public static String WEIGHT_UNIT = "KG";
	
	public ProductInfo() {}
	public ProductInfo(String code,String name) {
		this.code = code ;
		this.shortName = name ;
	}
	
	public ProductInfo(String code,String name,String barCode,String longName,BigDecimal weight ) {
		this(code,name);
		this.barCode = barCode ;
		this.longName = longName ;
		this.weight = weight ;
	}
	
	@Column(name = "p_code", nullable=false, length=20, unique = true )
    @NotNull(message="code must not be null or empty.")
	@Size(min=1,max=10)
	private String code;
	
	@Column(name = "s_name", nullable=false, length=60 )
    @NotNull(message="name must not be null or empty.")
	@Size(min=1,max=30)
	private String shortName;
	
	@Column(name = "bar_code", nullable=true, length=30 )
	private String barCode ;
	
	@Column(name = "l_code", nullable=true, length=200 )
	private String longName;
	
	@Column(name = "weight", nullable=false )
	private BigDecimal weight = new BigDecimal("1");

	@Column(name = "picture", nullable=true, length=120 )
	private String picture ;
	
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public String getShortName() {
		return shortName;
	}
	public void setShortName(String shortName) {
		this.shortName = shortName;
	}
	public String getBarCode() {
		return barCode;
	}
	public void setBarCode(String barCode) {
		this.barCode = barCode;
	}
	public String getLongName() {
		return longName;
	}
	public void setLongName(String longName) {
		this.longName = longName;
	}
	public BigDecimal getWeight() {
		return weight;
	}
	public void setWeight(BigDecimal weight) {
		this.weight = weight;
	}
	public String getPicture() {
		return picture;
	}
	public void setPicture(String picture) {
		this.picture = picture;
	}
	
	@Override
	public String toString() {
		return "Code:" + this.code + "==shortName:" + this.shortName ;
	}
	@Override
	boolean businessEquals(Object p) {
		if (!(p instanceof ProductInfo)) return false ;
		
		ProductInfo cp = (ProductInfo)p;
        
        if (this.code == null || cp.code == null) return false;	
		return (this.code).equalsIgnoreCase(cp.code) ;
	}	
}
